//
//  NoticecountViewController.m
//  ChatDemo-UI2.0
//
//  Created by 薛子 on 16/4/5.
//  Copyright © 2016年 薛子. All rights reserved.
//

#import "NoticecountViewController.h"
#import "NoticeCountTableViewCell.h"
#import "DetailHvkViewController.h"
#import "noReadModel.h"
#import "noReadListViewCell.h"


@interface NoticecountViewController ()<UIAlertViewDelegate,pushStudentInfoDelegate>
{
    EmptyStateView *noemptyView;//未读空状态
    EmptyStateView *reademptyView;//已阅读空状态
    
}
@end

@implementation NoticecountViewController

- (id)init
{
    self = [super init];
    if (self) {
        
        self.hidesBottomBarWhenPushed = YES;
        
    }
    return self;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.navBar.nav_titleLabel.text=@"通知统计";
    self.view.backgroundColor=[UIColor whiteColor];
    self.automaticallyAdjustsScrollViewInsets=NO;
    
    UIBarButtonItem *backItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageWithOriginalName:@"back"] style:UIBarButtonItemStyleDone target:self action:@selector(back)];
    self.navigationItem.leftBarButtonItem = backItem;
    
    [self initArray];
   
    
    flag=YES;
    allNum=@"0";
    noreadNum=@"0";
    readNum=@"0";
    
    
    
    [self requestReadData];
    
    [self loadNoReadTable];
    
    [self requestData];
    [self loadTopView];
    
    // Do any additional setup after loading the view.
}
- (void)initArray
{
    dataArray=[NSMutableArray array];
    xuanzhongArray=[NSMutableArray array];
    checkArray=[NSMutableArray array];
    rdataArray=[NSMutableArray array];
}
-(void)loadNoReadTable
{
    
    _myTableView=[[UITableView alloc]initWithFrame:CGRectMake(0,168+64, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height-110-168-64) style:UITableViewStylePlain];
    _myTableView.delegate=self;
    _myTableView.dataSource=self;
    _myTableView.showsVerticalScrollIndicator=NO;
    _myTableView.bounces=NO;
    _myTableView.separatorStyle=UITableViewCellSeparatorStyleNone;
    _myTableView.backgroundColor=RGBACOLOR(240, 239, 245, 1);
    [self.view addSubview:_myTableView];
    
    noemptyView = [[EmptyStateView alloc] initWithFrame:CGRectMake((SCREENWIDTH-120)/2, (_myTableView.frame.size.height)/2-70, 120, 110) andBackImage:@"participationlist_empty" andBottomStr:@"全体宝宝已读"];
    [_myTableView addSubview:noemptyView];
    
    if (_model.smssum>0) {
        sendMesImage=[[UIImageView alloc]initWithFrame:CGRectMake(12,[UIScreen mainScreen].bounds.size.height-20-38-10-27, 15, 15)];
        sendMesImage.image=[UIImage imageNamed:@"choose_message_nor_"];
        isSend=NO;
        [self.view addSubview:sendMesImage];
        
        
        sendLale=[[UILabel alloc]initWithFrame:CGRectMake(sendMesImage.frame.origin.x+sendMesImage.frame.size.width+15,sendMesImage.frame.origin.y, 200, 15)];
        sendLale.text=@"同时发送短信通知";
        sendLale.font=[UIFont systemFontOfSize:15];
        sendLale.textColor=RGBACOLOR(59, 59, 59, 1);
        [self.view addSubview:sendLale];
        
        sendMes=[UIButton buttonWithType:UIButtonTypeCustom];
        sendMes.frame=CGRectMake(12,[UIScreen mainScreen].bounds.size.height-20-38-10-27, 240, 15);
        [sendMes addTarget:self action:@selector(sendMessageAction:) forControlEvents:UIControlEventTouchUpInside];
        [self.view addSubview:sendMes];
    }
    allSelectBtn=[UIButton buttonWithType:UIButtonTypeCustom];
    allSelectBtn.frame=CGRectMake([UIScreen mainScreen].bounds.size.width-64,[UIScreen mainScreen].bounds.size.height-20-38-10-27, 52, 23);
    
    [allSelectBtn setImage:[UIImage imageWithOriginalName:@"all_choose_press_"] forState:UIControlStateNormal];
    
    [allSelectBtn addTarget:self action:@selector(selectTouchAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:allSelectBtn];
    
    
    sureBtn=[UIButton buttonWithType:UIButtonTypeCustom];
    sureBtn.frame=CGRectMake(12, [UIScreen mainScreen].bounds.size.height-20-38, [UIScreen mainScreen].bounds.size.width-24, 38);
    sureBtn.layer.cornerRadius=5;
    [sureBtn setTitle:@"再次通知" forState:UIControlStateNormal];
    [sureBtn addTarget:self action:@selector(secondNoticeAction:) forControlEvents:UIControlEventTouchUpInside];
    [sureBtn setBackgroundColor:RGBACOLOR(0, 180, 255, 1)];
    [self.view addSubview:sureBtn];
    
}
-(void)loadReadTable
{
    
    _myreadTableView=[[UITableView alloc]initWithFrame:CGRectMake(0,168+64, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height-64-168) style:UITableViewStylePlain];
    _myreadTableView.delegate=self;
    _myreadTableView.dataSource=self;
    _myreadTableView.showsVerticalScrollIndicator=NO;
    _myreadTableView.bounces=NO;
    _myreadTableView.separatorStyle=UITableViewCellSeparatorStyleNone;
    _myreadTableView.backgroundColor=RGBACOLOR(240, 239, 245, 1);
    [self.view addSubview:_myreadTableView];
    
    reademptyView = [[EmptyStateView alloc] initWithFrame:CGRectMake((SCREENWIDTH-120)/2, (_myreadTableView.frame.size.height-110)/2-70, 120, 110) andBackImage:@"participationlist_empty" andBottomStr:@"全体宝宝未读"];
    [_myreadTableView addSubview:reademptyView];

}
-(void)loadTopView
{
    UIView *back=[[UIView alloc]initWithFrame:CGRectMake(0,64, [UIScreen mainScreen].bounds.size.width, 168)];
    
    UIView *view01=[[UIView alloc]initWithFrame:CGRectMake(0, 0, back.frame.size.width, 105)];
    UILabel *courseLabel=[[UILabel alloc]initWithFrame:CGRectMake(12, 9, 150, 17)];
    courseLabel.text= _model.title;
    courseLabel.font=[UIFont boldSystemFontOfSize:17];
    courseLabel.textColor=RGBACOLOR(59, 59, 59, 1);
    [view01 addSubview:courseLabel];
    
    
    UILabel *timelabel=[[UILabel alloc]initWithFrame:CGRectMake(SCREENWIDTH-12-100, 9, 100, 11)];
    timelabel.text=[Utils getDataStringWithoutSecondString:_model.jointime];
    timelabel.textAlignment=NSTextAlignmentRight;
    timelabel.font=[UIFont systemFontOfSize:11];
    timelabel.textColor=RGBACOLOR(151, 151, 151, 1);
    [view01 addSubview:timelabel];
    
    UILabel *ContentLabe=[[UILabel alloc]initWithFrame:CGRectMake(12, courseLabel.frame.origin.y+courseLabel.frame.size.height+11,SCREENWIDTH-24, 36)];
    if (_model.scontent.length==0) {
        ContentLabe.text=@"通知内容,请点击进入查看图片信息。";
    }
    else
    {
        ContentLabe.text=_model.scontent;
    }
    ContentLabe.font=[UIFont systemFontOfSize:15];
    ContentLabe.numberOfLines=2;
    ContentLabe.textColor=RGBACOLOR(59, 59, 59, 1);
    [view01 addSubview:ContentLabe];
    
    UILabel *sourceLabel=[[UILabel alloc]initWithFrame:CGRectMake(12, ContentLabe.frame.origin.y+ContentLabe.frame.size.height+11, SCREENWIDTH-24-52-18, 12)];
    sourceLabel.text=[NSString stringWithFormat:@"发送对象：%@",_model.tousername
                      ];
    sourceLabel.font=[UIFont systemFontOfSize:12];
    sourceLabel.textColor=RGBACOLOR(151, 151, 151, 1);
    [view01 addSubview:sourceLabel];
    
    UILabel *detailLabel=[[UILabel alloc]initWithFrame:CGRectMake(SCREENWIDTH-12-52, sourceLabel.frame.origin.y, 60, 13)];
    detailLabel.text=@"查看详情";
    detailLabel.font=[UIFont systemFontOfSize:13];
    detailLabel.textAlignment=NSTextAlignmentRight;
    detailLabel.textColor=RGBACOLOR(56, 173, 255, 1);
    [view01 addSubview:detailLabel];
    
    UIImageView *line=[[UIImageView alloc]initWithFrame:CGRectMake(0, view01.frame.size.height-0.5, [UIScreen mainScreen].bounds.size.width,0.5)];
    line.backgroundColor=RGBACOLOR(199, 199, 204, 1);
    [view01 addSubview:line];
    
    UIView *view04=[[UIView alloc]initWithFrame:CGRectMake(0, view01.frame.origin.y+view01.frame.size.height, [UIScreen mainScreen].bounds.size.width, 10)];
    view04.backgroundColor=RGBACOLOR(239, 239, 244, 1);
    UIImageView *line2=[[UIImageView alloc]initWithFrame:CGRectMake(0, view04.frame.size.height-0.5, [UIScreen mainScreen].bounds.size.width,0.5)];
    line2.backgroundColor=RGBACOLOR(199, 199, 204, 1);
    [view04 addSubview:line2];
    
    
    UIView *view02=[[UIView alloc]initWithFrame:CGRectMake(0, view04.frame.origin.y+view04.frame.size.height, [UIScreen mainScreen].bounds.size.width, 54)];
    
    UIImageView *imageback=[[UIImageView alloc]initWithFrame:CGRectMake(60, 12, SCREENWIDTH-120, 30)];
    imageback.layer.borderWidth=1;
    imageback.layer.borderColor=RGBACOLOR(56, 173, 255, 1).CGColor;
    imageback.layer.cornerRadius=5;
    imageback.userInteractionEnabled=YES;
    
    
    readBtn=[[UIButton alloc]initWithFrame:CGRectMake(1, 1, imageback.frame.size.width/2-1, 28)];
    [readBtn setTitle:[NSString stringWithFormat:@"已读(%@)",readNum] forState:UIControlStateNormal];
    [readBtn setTitleColor:RGBACOLOR(57, 173, 255, 1) forState:UIControlStateNormal];
    [readBtn addTarget:self action:@selector(pushReadList:) forControlEvents:UIControlEventTouchUpInside];
    readBtn.titleLabel.font=[UIFont systemFontOfSize:14];
    [imageback addSubview:readBtn];
    
    noreadBtn=[[UIButton alloc]initWithFrame:CGRectMake(imageback.frame.size.width/2, 1, imageback.frame.size.width/2-1, 28)];
    [noreadBtn setTitle:[NSString stringWithFormat:@"未读(%@)",noreadNum] forState:UIControlStateNormal];
    [noreadBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [noreadBtn addTarget:self action:@selector(pushnoReadBtnList:) forControlEvents:UIControlEventTouchUpInside];
    [noreadBtn setBackgroundColor:RGBACOLOR(57, 173, 255, 1)];
    noreadBtn.titleLabel.font=[UIFont systemFontOfSize:14];
    [imageback addSubview:noreadBtn];
    
    [view02 addSubview:imageback];
    
    view01.backgroundColor=[UIColor whiteColor];
    view02.backgroundColor=[UIColor whiteColor];
    
    UIButton *todetailBtn=[UIButton buttonWithType:UIButtonTypeCustom];
    todetailBtn.frame=CGRectMake(0, 0, back.frame.size.width,105);
    [todetailBtn addTarget:self action:@selector(todetailVC:) forControlEvents:UIControlEventTouchUpInside];
    
    
    
    [view01 addSubview:line];
    [back addSubview:view01];
    [back addSubview:view02];
    [back addSubview:view04];
    [back addSubview:todetailBtn];
    [self.view addSubview:back];
}

-(void)sendMessageAction:(UIButton *)sender
{
    isSend=!isSend;
    if (isSend) {
        sendMesImage.image=[UIImage imageNamed:@"choose_message_press_"];
    }else
    {
        sendMesImage.image=[UIImage imageNamed:@"choose_message_nor_"];
    }
}
-(void)secondNoticeAction:(UIButton *)sender
{

    NSMutableArray *XIDArray=[NSMutableArray array];
    for (int i=0; i<[dataArray count]; i++) {
        noReadModel *model=[dataArray objectAtIndex:i];
        if (model.check) {
            [XIDArray addObject:[NSString stringWithFormat:@"%ld",(long)model.studentid]];
        }
    }
    NSString *gouxuanStr=[XIDArray componentsJoinedByString:@","];
    if (XIDArray.count==0) {
        [Utils alertViewWithMessage:@"请选择宝宝！"];
        return;
    }
    NSMutableDictionary * dict = [[NSMutableDictionary alloc] initWithCapacity:0];
    [dict setObject:@"sy_info_remindagain" forKey:@"method"];
    
    [dict setObject:_model.infoid forKey:@"infoid"];
    [dict setObject:_model.classid forKey:@"classid"];
    [dict setObject:gouxuanStr forKey:@"students"];
    if (isSend==YES) {
        [dict setObject:gouxuanStr forKey:@"sendsmsstudents"];
    }
    [dict setObject:USERID forKey:@"userid"];
    
    [Utils get:nil parameters:dict success:^(NSInteger recode, id resposeJson){
        
        NSDictionary *remindagaindic = (NSDictionary *)resposeJson;

        [Utils alertViewWithMessage:[remindagaindic objectForKey:@"re_info"]];
       
        
    } failure:^(NSInteger recode, NSError * error){
        
        [self showHint:@"网络异常,请稍后重试!"];
    }];

}
-(void)requestData
{
    NSMutableDictionary * dict = [[NSMutableDictionary alloc] initWithCapacity:0];
    [dict setObject:@"api_info_noreadlist" forKey:@"method"];
    [dict setObject:@"2000" forKey:@"pagesize"];
    [dict setObject:@"1" forKey:@"pageno"];
    [dict setObject:_model.infoid forKey:@"infoid"];
    [dict setObject:_model.classid forKey:@"classid"];
    [dict setObject:@"0" forKey:@"studentid"];
    [dict setObject:USERID forKey:@"userid"];
    
    [Utils get:nil parameters:dict success:^(NSInteger recode, id resposeJson){
        
        self->Infodict = (NSDictionary *)resposeJson;
        self->noreadNum=[self->Infodict objectForKey:@"re_noreadnum"];
        [self->noreadBtn setTitle:[NSString stringWithFormat:@"未读(%@)",self->noreadNum] forState:UIControlStateNormal];
        
        NSArray * array = [self->Infodict objectForKey:@"re_data"];
        [self->dataArray removeAllObjects];
        if (array.count>0) {
            self->sureBtn.hidden=NO;
            self->allSelectBtn.hidden=NO;
            [self->noemptyView hideEmptyImage];
            for (NSDictionary *dic in array) {
                noReadModel *model=[noReadModel mj_objectWithKeyValues:dic];
                model.check=YES;
                
                [self->dataArray addObject:model];
                
            }
            
            self->count=(int)self->dataArray.count;
             self->_myTableView.backgroundColor=RGBACOLOR(240, 239, 245, 1);
        }else
        {
            self->sureBtn.hidden=YES;
            self->allSelectBtn.hidden=YES;
            if (self->_model.smssum>0) {
                self->sendMesImage.hidden=YES;
                self->sendLale.hidden=YES;
                self->sendMes.hidden=YES;
            }
//            [self initNoworkView];
            [self->noemptyView showEmptyImage];
             self->_myTableView.backgroundColor=[UIColor whiteColor];
        }
        [self->_myTableView reloadData];
        
        
        
    } failure:^(NSInteger recode, NSError * error){
        
    }];

}
-(void)requestReadData
{
    NSMutableDictionary * dict = [[NSMutableDictionary alloc] initWithCapacity:0];
    [dict setObject:@"api_info_readlist" forKey:@"method"];
    [dict setObject:@"200" forKey:@"pagesize"];
    [dict setObject:@"1" forKey:@"pageno"];
    [dict setObject:_model.infoid forKey:@"infoid"];
    [dict setObject:_model.classid forKey:@"classid"];
    [dict setObject:@"0" forKey:@"studentid"];
    [dict setObject:USERID forKey:@"userid"];
    
    [Utils get:nil parameters:dict success:^(NSInteger recode, id resposeJson){
        
        self->rInfodict = (NSDictionary *)resposeJson;
        self->readNum=[self->rInfodict objectForKey:@"re_readnum"];
        [self->readBtn setTitle:[NSString stringWithFormat:@"已读(%@)",self->readNum]  forState:UIControlStateNormal];
        NSArray * array = [self->rInfodict objectForKey:@"re_data"];
        
        [self->rdataArray removeAllObjects];
        
        if (array.count>0) {
//            [self->noreadworkView removeFromSuperview];
//            [self->noworkView removeFromSuperview];
            [self->reademptyView hideEmptyImage];
            for (NSDictionary *dic in array) {
                noReadModel *model=[noReadModel mj_objectWithKeyValues:dic];
                model.check=YES;
                [self->rdataArray addObject:model];
            }
            self->_myreadTableView.backgroundColor=RGBACOLOR(240, 239, 245, 1);
        }else
        {
//            [self initNoworkView];
            [self->reademptyView showEmptyImage];
            self->_myreadTableView.backgroundColor=[UIColor whiteColor];
        }
        
        [self->_myreadTableView reloadData];
        
        
    } failure:^(NSInteger recode, NSError * error){
        
    }];
    
}


#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    if (tableView==_myTableView) {
        return [dataArray count];
    }else
    {
        return [rdataArray count];
    }
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath

{
    return 44;
}

-(void)todetailVC:(UIButton *)sender
{
    DetailHvkViewController *view=[[DetailHvkViewController alloc]init];
    view.model=_model;
    [self.navigationController pushViewController:view animated:YES];
    
}
-(void)selectTouchAction:(UIButton *)sender
{
    //flag=yes 未全选；=no为全部取消
    //全选
    flag=!flag;
    if (flag==YES) {
        [allSelectBtn setImage:[UIImage imageWithOriginalName:@"all_choose_press_"] forState:UIControlStateNormal];
        count=(int)dataArray.count;
        if (dataArray.count>0) {
            for ( int i=0;i<dataArray.count;i++) {
                noReadModel *model=[dataArray objectAtIndex:i];
                model.check=YES;
                [dataArray replaceObjectAtIndex:i withObject:model];
            }
        }
        
    }else
    {
        [allSelectBtn setImage:[UIImage imageNamed:@"all_choose_"] forState:UIControlStateNormal];
        count=0;
        for ( int i=0;i<dataArray.count;i++) {
            noReadModel *model=[dataArray objectAtIndex:i];
            model.check=NO;
            [dataArray replaceObjectAtIndex:i withObject:model];
        }
    }
    [_myTableView reloadData];

}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    static NSString *cellIndentifier=@"cell";
    
    noReadListViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIndentifier];
    
    if (cell==nil) {
        cell = [[noReadListViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIndentifier];
        
    }
    cell.selectionStyle=UITableViewCellSelectionStyleNone;//取消选择状态
    cell.delegate=self;
    cell.index=indexPath;
    
    if (!isread) {
        noReadModel *model=[dataArray objectAtIndex:indexPath.row];
        NSString *  nameStr=model.studentname;
        
        cell.nameLabel.text=nameStr;
        if (![model.logo hasPrefix:@"http"]) {
            NSString * logo = [REQUESTIMAGEURL stringByAppendingString:model.logo];
            [cell.headView.headImage sd_setImageWithURL:[NSURL URLWithString:logo]];
        }
        cell.headView.flag=NO;
        if (nameStr.length > 2) {
            nameStr = [nameStr substringFromIndex:nameStr.length-2];
        }
        cell.headView.namelabel.font=[UIFont systemFontOfSize:12];
        cell.headView.namelabel.text=nameStr;
        
        
        cell.selectBtn.tag=indexPath.row+100;
        cell.selectBtn.userInteractionEnabled=YES;
        if (model.check) {
            cell.selectImage.hidden=NO;
            cell.selectBtn.enabled=YES;
            cell.selectImage.image=[UIImage imageNamed:@"homeworks_allchoose_press_"];
        }
        else
        {
            cell.selectImage.hidden=NO;
            cell.selectBtn.enabled=YES;
            cell.selectImage.image=[UIImage imageWithOriginalName:@"homeworks_allchoose_nor_"];
        }
        
        cell.line.hidden=NO;
        cell.lLine.hidden=YES;
        
        if (indexPath.row==([dataArray count]-1)) {
            cell.line.hidden=YES;
            cell.lLine.hidden=NO;
        }
        [cell.selectBtn addTarget:self action:@selector(dianjiTouchAction:) forControlEvents:UIControlEventTouchUpInside];
    }else
    {
        noReadModel *model=[rdataArray objectAtIndex:indexPath.row];
        NSString *  nameStr=model.studentname;
        
        
        cell.nameLabel.text=nameStr;
        
        if (![model.logo hasPrefix:@"http"]) {
            NSString * logo = [REQUESTIMAGEURL stringByAppendingString:model.logo];
            [cell.headView.headImage sd_setImageWithURL:[NSURL URLWithString:logo]];
        }
        
        cell.headView.flag=NO;
        if (nameStr.length > 2) {
            nameStr = [nameStr substringFromIndex:nameStr.length-2];
        }
        cell.headView.namelabel.font=[UIFont systemFontOfSize:12];
        cell.headView.namelabel.text=nameStr;
        cell.selectImage.hidden=YES;
        cell.selectBtn.enabled=NO;
        
        cell.line.hidden=NO;
        cell.lLine.hidden=YES;
        
        if (indexPath.row==([rdataArray count]-1)) {
            cell.line.hidden=YES;
            cell.lLine.hidden=NO;
        }
    }
    
    return cell;
}

-(void)dianjiTouchAction:(UIButton *)sender
{

    noReadListViewCell *cell=[_myTableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:sender.tag-100 inSection:0]];//获取当前点击cell
    int row=(int)(sender.tag-100);
    noReadModel *model=[dataArray objectAtIndex:row];
    model.check=!model.check;
    if (!model.check) {
        count--;
        [dataArray replaceObjectAtIndex:row withObject:model];
        [allSelectBtn setImage:[UIImage imageWithOriginalName:@"all_choose_"] forState:UIControlStateNormal];
        flag=NO;
        
        
    }else
    {
        count++;
        [dataArray replaceObjectAtIndex:row withObject:model];
        if (count==[dataArray count]) {
            [allSelectBtn setImage:[UIImage imageWithOriginalName:@"all_choose_press_"] forState:UIControlStateNormal];
            flag=YES;
        }
    }
    if (model.check) {
        cell.selectImage.image=[UIImage imageWithOriginalName:@"homeworks_allchoose_press_"];
    }else
    {
        cell.selectImage.image=[UIImage imageWithOriginalName:@"homeworks_allchoose_nor_"];
    }
   
}
-(void)initNoworkView{
    
    if (isread) {
        noworkView = [[UIView alloc] initWithFrame:CGRectMake((SCREENWIDTH-185)/2, (_myreadTableView.frame.size.height-185)/2 , SCREENWIDTH, SCREENHEIGH-64-168)];
       
    }else
    {
        noreadworkView= [[UIView alloc] initWithFrame:CGRectMake((SCREENWIDTH-185)/2, (_myTableView.frame.size.height-185)/2 , 185, 185)];

    }
    
    noworkView.backgroundColor = [UIColor clearColor];
    
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    [btn sizeToFit];
    btn.frame = CGRectMake(0, 0, 185, 185);
    if (isread) {
        [btn setImage:[UIImage imageNamed:@"no_read_"] forState:UIControlStateNormal];
        btn.enabled = NO;
        [noworkView addSubview:btn];
    }else
    {
        [btn setImage:[UIImage imageNamed:@"all_read_"] forState:UIControlStateNormal];
        btn.enabled = NO;
        [noreadworkView addSubview:btn];
    }
    
    
    
    
    if (isread) {
        [self->_myreadTableView addSubview:self->noworkView];
    }else
    {
        [self->_myTableView addSubview:self->noreadworkView];
    }
}


-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
//    [self.navigationController popViewControllerAnimated:YES];
}

-(void)back
{
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(void)pushReadList:(UIButton *)sender
{
    
    [readBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [readBtn setBackgroundColor:RGBACOLOR(57, 173, 255, 1)];
    
    [noreadBtn setTitleColor:RGBACOLOR(57, 173, 255, 1) forState:UIControlStateNormal];
    [noreadBtn setBackgroundColor:[UIColor clearColor]];
    _myTableView.hidden=YES;
    if (!isread) {
        self->sureBtn.hidden=YES;
        self->allSelectBtn.hidden=YES;
        if (self->_model.smssum>0) {
            self->sendMesImage.hidden=YES;
            self->sendLale.hidden=YES;
            self->sendMes.hidden=YES;
        }
        [self loadReadTable];
        [self requestReadData];
    }
    isread=YES;
}

-(void)pushnoReadBtnList:(UIButton *)sender
{
    
    [noreadBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [noreadBtn setBackgroundColor:RGBACOLOR(57, 173, 255, 1)];
    
    flag=YES;//默认全选
    [allSelectBtn setImage:[UIImage imageWithOriginalName:@"all_choose_press_"] forState:UIControlStateNormal];
  
    [readBtn setTitleColor:RGBACOLOR(57, 173, 255, 1) forState:UIControlStateNormal];
    [readBtn setBackgroundColor:[UIColor clearColor]];
    if (isread) {
        [_myreadTableView removeFromSuperview];
        _myTableView.hidden=NO;
        [self requestData];
    }
    isread=NO;
    
}

-(void)pushStudentInfoVC:(NSIndexPath *)indexPath
{
    
}


@end
